package app1.rapidsquare.com.database;

import android.app.IntentService;
import android.content.Intent;

import app1.rapidsquare.com.core.ConnectionDetector;
import app1.rapidsquare.com.Utility.Utility;

/**
 * Created by Hikmat on 14.08.2014.
 */
public class AgileSyncService extends IntentService {


    private ConnectionDetector mConnectionDetector;

    public AgileSyncService() {
        super("AgileNYC");

    }

    @Override
    protected void onHandleIntent(Intent intent) {
        try {
            mConnectionDetector = new ConnectionDetector(
                    getApplicationContext());

            if (mConnectionDetector.getConnectingStatus()) {

                AgileEventsProvider eventProvider = new AgileEventsProvider(
                        getApplicationContext());
                eventProvider.Update();

                AgileUserProvider usersProvider = new AgileUserProvider(
                        getApplicationContext());
                usersProvider.Update();


                AgileContactsProvider contactProvider = new AgileContactsProvider(
                        getApplicationContext());
                contactProvider.Update();
            }

        } catch (Exception ex) {
            Utility.Log("AgileSyncService -> onHandleIntent ", ex);
        } finally {
            stopSelf();
        }
    }
}
